package servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.TarefaDao;
import dao.UsuarioDao;

import model.Tarefa;

import antlr.Parser;

/**
 * Servlet implementation class cadastroTarefa
 */
public class cadastroTarefa extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public cadastroTarefa() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String nomeTarefa = request.getParameter("nomeTarefa");
		String prazo = request.getParameter("prazo");
		String relevancia = request.getParameter("relevancia");
		Long id = Long.parseLong(request.getParameter("id"));

		Tarefa tarefa = new Tarefa();
		tarefa.setNomeTarefa(nomeTarefa);
		tarefa.setPrazo(prazo);
		tarefa.setRelevancia(relevancia);
		tarefa.setData(new Date());
		tarefa.setId_usuario(id);

		if(nomeTarefa.equals("") || prazo.equals("") || relevancia.equals("")){
			RequestDispatcher rd = request.getRequestDispatcher("dadosIncompletos.jsp");
			rd.include(request, response);
		}
		else{

			TarefaDao.adicionarTarefa(tarefa);

			System.out.println("Tarefa cadastrada");
			RequestDispatcher rd = request.getRequestDispatcher("listaDeTarefasPendentes.jsp");
			rd.include(request, response);
		}
	}

}
